ggplot(Trading_Volume) +
geom_col(aes(x = Year, y = Trading_Volume), size = 1, color = "darkblue", fill = "white") +
#geom_col(aes(x = Year, y = Trading_Volume), size = 1, color = "darkblue", fill = "white") +
#scale_y_continuous(sec.axis = sec_axis(~., name = "Loan Amount (USD bn)")) +
theme_bw( ) +
ylab("Loan Amount (USD Bn)") +
xlab("")+
theme(text = element_text(size=8), legend.position=c(0.9,0.9)) +
#ggtitle("US Annual Secondary Trading Volume")+
theme(strip.text.x = element_text(size=10),
strip.text.y = element_text(size=10),
strip.background = element_rect(colour="white", fill="white")) +
theme(axis.text=element_text(size=10)) +
theme(axis.title.x = element_text(size = 10)) +
theme(axis.title.y = element_text(size = 10)) +
theme(plot.title = element_text(color="black", size=10, face = "bold")) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
library(readr)
TRACE_monthly_ytm_wSize <- read_csv("TRACE_monthly_ytm_wSize.csv",
col_types = cols(...1 = col_skip(), ...2 = col_skip(),
date_m = col_date(format = "%Y-%m-%d")))
View(TRACE_monthly_ytm_wSize)
library(readr)
ytm_bond_combined_v2023_07_27 <- read_csv("ytm_bond_combined_v2023-07-27.csv",
col_types = cols(date_m = col_date(format = "%Y-%m-%d")))
View(ytm_bond_combined_v2023_07_27)
#setup and load data
rm(list=ls())
library(tidyverse); library(readxl); library(tidylog); library(haven); library(tidyr); library(haven); library(purrr); library(stats); library(plm); library(sandwich); library(lmtest); library(stargazer); library(data.table); library(lubridate)  ; library(ggpubr)
options(scipen=999)
options(digits=6)
#Assign dplyr verbs
select <- dplyr::select
rename <- dplyr::rename
mutate <- dplyr::mutate
filter <- dplyr::filter
arrange <- dplyr::arrange
distinct <- dplyr::distinct
group_by <- dplyr::group_by
summarise <- dplyr::summarise
lag <- dplyr::lag
#Define directories
global <- "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT"
TRACE_monthly_ytm_wSize <- read_csv("C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT/Data/TRACE_monthly_ytm_wSize.csv",
col_types = cols(...1 = col_skip(), ...2 = col_skip(),
date_m = col_date(format = "%Y-%m-%d")))
ytm_bond_combined_v2023_07_27 <- read_csv("C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT/Data/ytm_bond_combined_v2023-07-27.csv",
col_types = cols(date_m = col_date(format = "%Y-%m-%d")))
View(TRACE_monthly_ytm_wSize)
View(TRACE_monthly_ytm_wSize)
View(TRACE_monthly_ytm_wSize)
View(ytm_bond_combined_v2023_07_27)
TRACE_monthly_ytm_wSize <- TRACE_monthly_ytm_wSize %>%
select(date_m, cusip_id, ISSUE_ID:avg_at )
ytm_bond_combined_v2023_07_27 <- left_join(ytm_bond_combined_v2023_07_27, TRACE_monthly_ytm_wSize, by=c("cusip_id"="cusip_id", "date_m"="date_m"))
library(readr)
bond_level_gvkey <- read_csv("bond_level_gvkey_full_list_v2023-08-23.csv")
View(bond_level_gvkey)
write.csv(ytm_bond_combined_v2023_07_27, "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT/Data/ytm_bond_combined.csv")
library(readr)
bond_market_composition <- read_csv("C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT/Data/bond_market_composition.csv")
LSTA_monthly_ytm <- read_csv(paste0(global, "/Processed/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
LSTA_monthly_ytm <- read_csv(paste0(global, "/Data/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
#Calculate distribution
compustat_size <- LSTA_monthly_ytm %>%
select(date_m, LIN, gvkey_comb, fyear, avg_at) %>%
mutate(size_bucket = ifelse( avg_at <= 1000 , 1000, avg_at )) %>%
mutate(size_bucket = ifelse( size_bucket > 1000 & size_bucket <=2000 , 2000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 2000 & size_bucket <=4000 , 4000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 4000 & size_bucket <=6000 , 6000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 6000 & size_bucket <=8000 , 8000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 8000 & size_bucket <=10000 ,10000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 10000 & size_bucket <=12000 , 12000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 12000 & size_bucket <=14000 , 14000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 14000 & size_bucket <=16000 , 16000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 16000 & size_bucket <=18000 , 18000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 18000 & size_bucket <=20000 , 20000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 20000 , 25000, size_bucket ))
#Calculate distribution
compustat_size %>%
group_by(size_bucket) %>%
summarise(count=n()) %>%
filter(!is.na(size_bucket)) %>%
mutate(total = sum(count)) %>%
mutate(proportion = round(count/total,3)) %>%
mutate(check=sum(proportion))
#Load bond spreads
TRACE_monthly_ytm_1999_2020  <- read_csv(paste0(global, "/Data/final_panel_bonds.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
glimpse(TRACE_monthly_ytm_1999_2020)
#Calculate distribution
compustat_size <- TRACE_monthly_ytm_1999_2020 %>%
select(date_m, cusip_id, gvkey_ccl, fyear, avg_at) %>%
mutate(size_bucket = ifelse( avg_at <= 1000 , 1000, avg_at )) %>%
mutate(size_bucket = ifelse( size_bucket > 1000 & size_bucket <=2000 , 2000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 2000 & size_bucket <=4000 , 4000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 4000 & size_bucket <=6000 , 6000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 6000 & size_bucket <=8000 , 8000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 8000 & size_bucket <=10000 ,10000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 10000 & size_bucket <=12000 , 12000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 12000 & size_bucket <=14000 , 14000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 14000 & size_bucket <=16000 , 16000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 16000 & size_bucket <=18000 , 18000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 18000 & size_bucket <=20000 , 20000, size_bucket )) %>%
mutate(size_bucket = ifelse( size_bucket > 20000 , 25000, size_bucket ))
#Calculate distribution
compustat_size %>%
group_by(size_bucket) %>%
summarise(count=n()) %>%
filter(!is.na(size_bucket)) %>%
mutate(total = sum(count)) %>%
mutate(proportion = round(count/total,3)) %>%
mutate(check=sum(proportion))
#Clear user defined environment
rm(list=ls())
#Load packages
require(stargazer); require(lubridate); library(sandwich); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(lmtest); library(DescTools); library(fixest)
#options
options(digits=5)
options(stringsAsFactors = FALSE)
options(scipen=999)
#Assign dplyr verbs
select <- dplyr::select
rename <- dplyr::rename
mutate <- dplyr::mutate
filter <- dplyr::filter
arrange <- dplyr::arrange
distinct <- dplyr::distinct
group_by <- dplyr::group_by
summarise <- dplyr::summarise
list <- base::list
#Define directories
global <- "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT"
#Load
bond_level_gvkey <- read_csv(paste0(global, "/Data/final_panel_bonds.csv", ""),
col_types = cols(...1 = col_skip(), OFFERING_DATE = col_date(format = "%Y-%m-%d")))
View(bond_level_gvkey)
bond_level_gvkey <- bond_level_gvkey %>%
select(cusip_id, PERMNO, PERMCO, conm_ccl, gvkey_ccl, OFFERING_DATE, fyear)
#Collapse to GVKEY-Year level
bond_list <- bond_level_gvkey %>%
arrange(gvkey_ccl, fyear) %>%
distinct(gvkey_ccl, fyear) %>%
mutate(bond_1st_issued = 1) %>%
distinct(gvkey_ccl, .keep_all = T)
View(bond_list)
#Load
cmp <- read_csv(paste0(global, "/Data/final_panel_compustat.csv", ""),
col_types = cols(gvkey = col_number(),
datadate = col_date(format = "%d/%m/%Y")))
check <- cmp %>%
group_by(fyear) %>%
summarise(num_gvkey = n_distinct(gvkey))
#Remove Non-US Firms
cmp <- cmp %>%
filter(loc == "USA")
#Remove financials
cmp <- cmp %>%
filter(!sic %in% c(6000:6999)) %>%
filter(!sic %in% c(9990:9999))
#Join bond issuance year
cmp <- left_join(cmp, bond_list, by=c("gvkey"="gvkey_ccl","fyear"="fyear"))
#Fill in bond dummy
cmp <- cmp %>%
group_by(gvkey) %>%
fill(bond_1st_issued, .direction = "down")
rm(check)
#Check how many gvkey's each year in COMPUSTAT
check <- cmp %>%
group_by(fyear) %>%
mutate(obs = 1) %>%
summarise(n_obs_total = sum(obs))
#PLot
ggplot(data = check) +
geom_col(aes(x = fyear, y = n_obs_total)) +
theme_bw()+
ggtitle("Number of GVKEY's in COMPUSTAT")
#Check how many new gvkey's each quarter had bond outstanding issue a bond
check_b <- cmp %>%
filter(bond_1st_issued == 1) %>%
mutate(obs = 1) %>%
group_by(fyear) %>%
summarise(n_firms_bond_issuer = sum(obs))
#PLot
ggplot(data = check_b) +
geom_col(aes(x = fyear, y = n_firms_bond_issuer)) +
theme_bw()+
ggtitle("Number of GVKEY's in COMPUSTAT having ever issued a bond")
#proportion of firms with bond
check <- left_join(check, check_b, by=c("fyear"="fyear"))
check <- check %>%
mutate(prop = n_firms_bond_issuer / n_obs_total)
check %>%
filter(fyear > 1999) %>%
ggplot() +
geom_col(aes(x = fyear, y = prop)) +
theme_bw()+
ggtitle("Proportion of GVKEY's in COMPUSTAT having eveer issued a bond")
#PLot
g <- check %>%
filter(fyear > 1999) %>%
ggplot() +
geom_col(aes(x = fyear, y = 1- prop)) +
theme_bw()+
ggtitle("Proportion Non-bond Firms") +
theme(plot.title = element_text(size = 10))  +
xlab("")+
ylab("")
check %>%
filter(fyear > 1999) %>%
ggplot() +
geom_col(aes(x = fyear, y = 1- prop)) +
theme_bw()+
ggtitle("Proportion Non-bond Firms") +
theme(plot.title = element_text(size = 10))  +
xlab("")+
ylab("")
#LSTA data
LSTA_monthly_ytm <- read_csv(paste0(global, "/Data/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
View(LSTA_monthly_ytm)
#list of gvkeys of bank market firms
list_bank <- cmp %>%
filter(is.na(bond_1st_issued)) %>%
group_by(fyear) %>%
distinct(gvkey)
#List of gvkeys in LSTA
list_lsta <- LSTA_monthly_ytm %>%
group_by(fyear) %>%
distinct(gvkeyyy) %>%
mutate(num_bankfirms_in_lsta = 1)
#List of gvkeys in LSTA
list_lsta <- LSTA_monthly_ytm %>%
group_by(fyear) %>%
distinct(gvkey_comb) %>%
mutate(num_bankfirms_in_lsta = 1)
View(list_bank)
list_bank <- left_join(list_bank, list_lsta, by=c("fyear"="fyear", "gvkey"="gvkeyyy"))
list_bank <- left_join(list_bank, list_lsta, by=c("fyear"="fyear", "gvkey"="gvkey_comb"))
list_bank <- list_bank %>%
group_by(fyear) %>%
summarise(n_bankfirms_in_LSTA = sum(num_bankfirms_in_lsta, na.rm = T))
#Final compare
check <- left_join(check, list_bank, by=c("fyear"="fyear"))
check <- check %>%
mutate(n_bankfirms_not_in_lsta = n_firms_bank_issuer - n_bankfirms_in_LSTA)
View(check)
#LSTA data
LSTA_monthly_ytm <- read_csv(paste0(global, "/Data/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
n_gvkey <- LSTA_monthly_ytm %>%
group_by(fyear) %>%
distinct(gvkeyyy) %>%
mutate(obs = 1) %>%
group_by(fyear) %>%
summarise(n_gvkeys_in_LSTA = sum(obs, na.rm = T))
n_gvkey <- LSTA_monthly_ytm %>%
group_by(fyear) %>%
distinct(gvkey_comb) %>%
mutate(obs = 1) %>%
group_by(fyear) %>%
summarise(n_gvkeys_in_LSTA = sum(obs, na.rm = T))
#list of gvkeys in LSTA
n_list <- LSTA_monthly_ytm %>%
group_by(fyear) %>%
distinct(gvkey_comb)
#list of gvkeys of bank market firms
n_bank <- cmp %>%
filter(is.na(bond_1st_issued)) %>%
group_by(fyear) %>%
distinct(gvkey) %>%
mutate(n_bankfirm_in_cmo = 1)
n_list <- left_join(n_list, n_bank, by = c("fyear"="fyear", "gvkey-comb"="gvkey"))
n_list <- left_join(n_list, n_bank, by = c("fyear"="fyear", "gvkey_comb"="gvkey"))
n_list <- n_list %>%
group_by(fyear) %>%
summarise(n_bankfirms_in_cmp = sum(n_bankfirm_in_cmo, na.rm = T))
n_gvkey <- left_join(n_gvkey, n_list, by=c("fyear"="fyear"))
View(n_gvkey)
#Format date/market cap
#Start in 1985-12 to match ratings
cmp_ppe <- cmp %>%
filter(datadate > "1998-01-01")  %>%
select(gvkey, datadate, fyear, ppegt, bond_1st_issued)
cmp_ppe <- cmp_ppe %>%
group_by(fyear) %>%
mutate(ppegt_w = Winsorize(ppegt, na.rm = T, probs = c(0.05,0.95)))
summary(cmp_ppe$ppegt)
summary(cmp_ppe$ppegt_w)
#Dummy variable
cmp_ppe <- cmp_ppe %>%
mutate(bond_firm = ifelse(!is.na(bond_1st_issued),1,0),
bank_firm = ifelse(is.na(bond_1st_issued),1,0))
#Total share
total <- cmp_ppe %>%
group_by(fyear) %>%
summarise(total = sum(ppegt_w, na.rm = T))
bank <- cmp_ppe %>%
filter(bank_firm == 1) %>%
group_by(fyear) %>%
summarise(bank_firms = sum(ppegt_w, na.rm = T))
bond <- cmp_ppe %>%
filter(bond_firm == 1) %>%
group_by(fyear) %>%
summarise(bond_firms = sum(ppegt_w, na.rm = T))
#Plot
total <- left_join(total, bank)
total <- left_join(total, bond)
total <- total %>%
mutate(prop_PPE_bank_firms = bank_firms/total,
prop_PPE_bond_firms = bond_firms/total) %>%
filter(fyear > 1999)
b <- ggplot(data = total)+
geom_col(aes(x = fyear, y = prop_PPE_bank_firms))+
theme_bw()+
ggtitle("Plant,Property,Equipment") +
theme(plot.title = element_text(size = 10))  +
ylab("") +
xlab("")
ggplot(data = total)+
geom_col(aes(x = fyear, y = prop_PPE_bank_firms))+
theme_bw()+
ggtitle("Plant,Property,Equipment") +
theme(plot.title = element_text(size = 10))  +
ylab("") +
xlab("")
#Load
LSTA_monthly_ytm <- read_csv(paste0(global, "/Data/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
rm(list=ls())
require(quantmod); require(dynlm); require(AER); require(vars); require(forecast); require(stargazer); require(strucchange); require(xts); require(lubridate); require(fGarch); require(zoo); require(timeSeries); library(sandwich); require(car);library(fBasics); library(ggplot2); require(dplyr); require(tidyverse); library(readxl); library(sandwich); library(QuantPsyc); library(corrplot);library(plm); library(ggplot2); library(modelr)
library(ggpubr)
options(scipen=999)
#Assign dplyr verbs
select <- dplyr::select
rename <- dplyr::rename
mutate <- dplyr::mutate
filter <- dplyr::filter
arrange <- dplyr::arrange
distinct <- dplyr::distinct
group_by <- dplyr::group_by
summarise <- dplyr::summarise
lag <- dplyr::lag
#Define directories
global <- "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT"
#Load
LSTA_monthly_ytm <- read_csv(paste0(global, "/Data/final_panel_loans.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
TRACE_monthly_ytm_1999_2020 <- read_csv(paste0(global, "/Data/final_panel_bonds.csv", ""),
col_types = cols(...1 = col_skip(), date_m = col_date(format = "%Y-%m-%d")))
check <- LSTA_monthly_ytm %>%
group_by(BorrowerName) %>%
summarise(n=n())
#3,773 unique issuer ids
check <- LSTA_monthly_ytm %>%
filter(!is.na(gvkey_comb)) %>%
group_by(BorrowerName) %>%
summarise(n=n())
#2,030 public issuers
check <- LSTA_monthly_ytm%>%
filter(is.na(gvkey_comb)) %>%
group_by(BorrowerName) %>%
summarise(n=n())
#1,763 unique issuer_ids without gvkeys
check <- LSTA_monthly_ytm %>%
filter(!is.na(gvkey_comb)) %>%
group_by(gvkey_comb) %>%
summarise(n=n())
#1,776 unique gvkeys amongst pubblic issuers
check <- LSTA_monthly_ytm %>%
group_by(BorrowerName) %>%
summarise(n=n())
check <- LSTA_monthly_ytm %>%
filter(!is.na(gvkey_comb)) %>%
group_by(BorrowerName) %>%
summarise(n=n())
check <- LSTA_monthly_ytm%>%
filter(is.na(gvkey_comb)) %>%
group_by(BorrowerName) %>%
summarise(n=n())
check <- LSTA_monthly_ytm %>%
filter(!is.na(gvkey_comb)) %>%
group_by(gvkey_comb) %>%
summarise(n=n())
check <- TRACE_monthly_ytm_1999_2020 %>%
group_by(ISSUER_ID) %>%
summarise(n=n())
check <- TRACE_monthly_ytm_1999_2020 %>%
filter(!is.na(gvkey_ccl)) %>%
group_by(ISSUER_ID) %>%
summarise(n=n())
check <- TRACE_monthly_ytm_1999_2020 %>%
filter(is.na(gvkey_ccl)) %>%
group_by(ISSUER_ID) %>%
summarise(n=n())
check <- TRACE_monthly_ytm_1999_2020 %>%
filter(!is.na(gvkey_ccl)) %>%
group_by(gvkey_ccl) %>%
summarise(n=n())
#Loans
#Keep unique loan issuers 3,773
issuer_list <-  LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(BorrowerName, .keep_all = TRUE) %>%
filter(!is.na(BorrowerName))
#Keep unique loan issuers with GVKEY 1,776
loan_borrower_list <- LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(gvkey_comb, .keep_all = TRUE) %>%
filter(!is.na(gvkey_comb))
#Keep unique loan issuer gvkeys
loan_borrower_list <-  loan_borrower_list %>%
ungroup() %>%
select(gvkey_comb) %>%
distinct(gvkey_comb) %>%
mutate(loan = 1)
#Bonds
#Keep unique bond issuers 1,610
bond_borrower_list <-  TRACE_monthly_ytm_1999_2020 %>%
select(ISSUER_ID, gvkey_ccl, PROSPECTUS_ISSUER_NAME) %>%
distinct(gvkey_ccl, .keep_all = TRUE) %>%
filter(!is.na(gvkey_ccl))
bond_borrower_list <-  bond_borrower_list %>%
ungroup() %>%
select(gvkey_ccl) %>%
distinct(gvkey_ccl) %>%
mutate(bond = 1)
#Combine
all_gvkey <- full_join(bond_borrower_list, loan_borrower_list, by=c("gvkey_ccl"="gvkey_comb"))
check <- all_gvkey %>%
filter(bond == 1 )
#1610
check <- all_gvkey %>%
filter(loan == 1)
#1778
check <- all_gvkey %>%
filter(loan == 1 & bond ==1)
#569
View(all_gvkey)
View(LSTA_monthly_ytm)
#Keep unique loan issuers 3,773
issuer_list <-  LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(BorrowerName, .keep_all = TRUE) %>%
filter(!is.na(BorrowerName))
View(issuer_list)
#Keep unique loan issuers with GVKEY 1,776
loan_borrower_list <- LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(gvkey_comb, .keep_all = TRUE) %>%
filter(!is.na(gvkey_comb))
View(loan_borrower_list)
#Keep unique loan issuers with GVKEY 1,776
loan_borrower_list <- LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(gvkey_comb, .keep_all = TRUE) %>%
filter(!is.na(gvkey_comb))
#Keep unique loan issuer gvkeys
loan_borrower_list <-  loan_borrower_list %>%
ungroup() %>%
select(gvkey_comb) %>%
distinct(gvkey_comb) %>%
mutate(loan = 1)
View(bond_borrower_list)
#Keep unique loan issuers with GVKEY 1,776
loan_borrower_list <- LSTA_monthly_ytm %>%
ungroup() %>%
select(gvkey_comb, BorrowerName) %>%
distinct(gvkey_comb, .keep_all = TRUE) %>%
filter(!is.na(gvkey_comb))
View(bond_borrower_list)
library(readr)
all_gvkey <- read_csv("all_gvkey.csv")
View(all_gvkey)
all_gvkey <- all_gvkey %>%
select(-'...1')
library(readr)
final_panel_compustat <- read_csv("final_panel_compustat.csv")
View(final_panel_compustat)
library(readr)
final_panel_compustat <- read_csv("final_panel_compustat.csv",
col_types = cols(gvkey = col_number()))
View(final_panel_compustat)
final_panel_compustat <- left_join(final_panel_compustat, all_gvkey, by=c("gvkey"="gvkey_ccl"))
write.csv(final_panel_compustat, "C:/Users/asp.fi/Dropbox (CBS)/2019_Gilchrist and Zakrajsek/02 R Scripts/2024_RFS_Replication_TOSUBMIT/Data/final_panel_compustat.csv")
all_gvkey <- read_csv(paste0(global, "/Processed/final_panel_compustat.csv", ""))
all_gvkey <- read_csv(paste0(global, "/Data/final_panel_compustat.csv", ""))
distinct(gvkey, .keep_all = T )
all_gvkey <- all_gvkey %>%
select(gvkey, bond, loan, age, avg_at) %>%
distinct(gvkey, .keep_all = T )
View(all_gvkey)
all_gvkey <- all_gvkey %>%
select(gvkey, bond, loan, age, avg_at) %>%
distinct(gvkey, .keep_all = T ) %>%
filter(bond == 1 | loan == 1)
View(all_gvkey)
all_gvkey %>%
filter(bond == 1) %>%
mutate(mean_age = mean(age, na.rm = T))
#Under 5years
a <-  all_gvkey %>%
filter(bond == 1) %>%
filter(age <= 5) %>%
distinct(gvkey_ccl, .keep_all = T)
